﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;

namespace Oxage.Models
{
	/// <summary>
	/// Mapper to assign custom keys to actions.
	/// </summary>
	public class KeyboardMapper
	{
		private Dictionary<KeyboardChord, Action> map = new Dictionary<KeyboardChord, Action>();

		public void Add(KeyboardChord chord, Action action)
		{
			map.Add(chord, action);
		}

		public void Add(Key key, ModifierKeys modifiers, Action action)
		{
			var chord = new KeyboardChord()
			{
				Key = key,
				Modifiers = modifiers
			};
			map.Add(chord, action);
		}

		public Action Find(Key key, ModifierKeys modifiers)
		{
			var chord = map.Keys.FirstOrDefault(x => x.Key == key && x.Modifiers == modifiers);
			var action = (chord != null ? map[chord] : null);
			return action;
		}
	}
}
